﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace UploadBlobToAzure
{
    public partial class createBlobFileOrDir : Form
    {
        public List<string> blobList = new List<string>();
        public createBlobFileOrDir()
        {
            InitializeComponent();       
        }

        public void setDirOrFileRadio(string dirOrFile)
        {
            if (dirOrFile == "DIR")
            {
                radDir.Checked = true;
                radDir.Enabled = false;
                radFile.Enabled = false;
                txtFileName.Enabled = false;
                lblFile.Enabled = false;
            }
            else if(dirOrFile=="FILE")
            {
                radFile.Checked = true;
                radDir.Enabled = false;
                radFile.Enabled = false;
                lblDir.Enabled = false;
                txtDirName.Enabled = false;
            }            
        }
        public void setBlobList(List<string> m_blobList)
        {
            blobList.AddRange(m_blobList);
            cmbLocation.DataSource = blobList;
        }

        public string getLocation()
        {
            return cmbLocation.SelectedItem.ToString();
        }

        public string getDirectoryName()
        {
            return txtDirName.Text;
        }

        public string getFileName()
        {
            return txtFileName.Text;
        }

        private void btnCreateBlob_Click(object sender, EventArgs e)
        {
            if (cmbLocation.SelectedItem == "")
            {
                MessageBox.Show("Please select a location from the drop down");
            }
            if (txtDirName.Enabled==true)
            {
                if(txtDirName.Text == "")
                {
                    MessageBox.Show("Please enter a valid directory nane");
                    this.DialogResult = DialogResult.None;
                }
                if(txtDirName.Text==" ")
                {
                    MessageBox.Show("Please enter a valid directory name");
                    this.DialogResult = DialogResult.None;
                }
            }
            if (txtFileName.Enabled == true)
            {
                if (txtFileName.Text == "")
                {
                    MessageBox.Show("Please enter a valid file nane");
                    this.DialogResult = DialogResult.None;
                }
                if (txtFileName.Text == " ")
                {
                    MessageBox.Show("Please enter a valid file nane");
                    this.DialogResult = DialogResult.None;
                }
                if (txtFileName.Text.IndexOf(".") == -1)
                {
                    DialogResult dialogResult = MessageBox.Show("Are you sure the file is without extensions", "Attention", MessageBoxButtons.YesNo);
                    if (dialogResult == DialogResult.Yes)
                    {
                        this.Close();
                    }
                    else if (dialogResult == DialogResult.No)
                    {
                        this.DialogResult = DialogResult.None;
                    }                    
                }
            }

        }

        private void btnReset_Click(object sender, EventArgs e)
        {
            if (radDir.Checked)
            {
                radDir.Enabled = false;
                radFile.Enabled = false;
                txtFileName.Enabled = false;
                lblFile.Enabled = false;
            }
            else if (radFile.Checked)
            {
                
                radDir.Enabled = false;
                radFile.Enabled = false;
                lblDir.Enabled = false;
                txtDirName.Enabled = false;
            }            
        }




        
        
    }
}
